<template>
	<view class="page">
		<view class="head" v-if="spotList.length > 0">
			<picker :range="spotList" range-key="name" @change="changePicker">
				<view class="flex align-center" style="gap:10rpx;">
					{{spotList[spotIndex].name}}
					<image class="xla" src="/static/images/xla.png"></image>
				</view>
			</picker>
		</view>
		<view class="conter">
			<!-- <view class="thisMonth">本月</view> -->

			<picker mode="date" @change="changeTime($event,0)">
				<view>
					{{timeBetween[0]||'开始时间'}}
				</view>
			</picker>
			-
			<picker mode="date" @change="changeTime($event,1)">
				<view>
					{{timeBetween[1]||'结束时间'}}
				</view>
			</picker>
			<!-- <view class="thisMonth">
				<view class="flex align-center">
					时间筛选
					<image class="xla" src="/static/images/xla1.png"></image>
				</view>
			</view> -->
		</view>

		<view class="contersun" v-for="item,index in list" :key="index">
			<view class="flexa">
				<view class="text">
					<uni-icons type="shop" size="20"></uni-icons>
					{{item.shop.shopname}}
					<img src="@/static/images/news/bkm1.png" alt="">
				</view>
				<view class="text1">核销时间：{{item.time_text}}</view>
			</view>
			<view class="contentLayout">
				<img :src="$wanlshop.oss(item.goods.image)" alt="">
				<view class="item-right">
					<view>
						<view class="bunns">{{item.goods.title}}</view>
						<view>¥{{item.goods.price}}</view>
					</view>
					<view class="item-right-bottom">
						<view>{{item.goods.goods_sku_sn}}</view>
						<view>x{{item.goods.number}}</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="moreStatus"></uni-load-more>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				totalPage: 1,
				list: [],

				spotList: [],
				spotIndex: 0,

				timeFilter: [],
				timeFilterIndex: 0,

				timeBetween: ['', ''],
				
				moreStatus:'none'
			};
		},
		onLoad() {
			// this.getSpot()
		},
		mounted() {
			let date = new Date()

			let Y = date.getFullYear()
			let m = (date.getMonth() + 1 + '').padStart(2, '0')
			let d = (date.getDate() + '').padStart(2, '0')

			this.timeBetween = [
				`${Y}-${m}-01`,
				`${Y}-${m}-${d}`
			]

			this.getSpot()
		},
		onPullDownRefresh() {
			this.init()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			changePicker(e) {
				console.log(e,'899898989');
				this.spotIndex = e.detail.value
				console.log('-=-=-=', this.spotIndex)
				// this.$forceUpdate()
				this.init()
			},
			changeTime(e, index) {
				this.timeBetween[index] = e.detail.value
				this.$forceUpdate()
				this.init()
				// console.log('-=-=-=e',e)
			},
			getSpot() {

				uni.request({
					url: '/wanlshop/order/mySpot',
					success: res => {
						this.spotList = res.data
						// this.spotList.unshift({
						// 	name: '选择店铺',
						// 	id: ''
						// })
						console.log(this.spotList,'99888898989');
						
						this.init()
					}
				})
			},
			init() {
				this.page = 1
				this.totalPage = 1
				this.getList()
			},
			getList() {
				if (this.page > this.totalPage) return
				console.log('-=-=-=list', )
				this.moreStatus = 'loading'
				let data = {
					time: this.timeBetween.join(',')
				}

				if (this.spotIndex !== '') {
					data.spot_id = this.spotList[this.spotIndex].id
				}
				uni.request({
					url: '/wanlshop/product/qrcodelog',
					data: {
						page: this.page,
						...data
					},
					success: res => {
						let list = res.data.data
						if (this.page > 1) {
							list = this.list.concat(list)
						}
						this.list = list
						this.page++
						this.totalPage = res.data.last_page
						// console.log('-=-=-=res',res)
					},
					complete: t => {
						uni.stopPullDownRefresh()
						this.moreStatus = 'none'
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		
			background-color: #EDEDED;
	}
	.xla {
		width: 30rpx;
		height: 30rpx;
	}

	.page {
		padding: 20rpx;

		.head {
			margin-top: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 92rpx;
			background: #2C4076;
			border-radius: 16rpx;
			color: white;
			gap: 25rpx;
		}

		.conter {
			margin-top: 20rpx;
			gap: 40rpx;
			display: flex;
			justify-content: center;

			.thisMonth {
				display: flex;
				align-items: center;
				gap: 20rpx;
			}
		}

		.contersun {
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 15rpx;
			margin-top: 20rpx;


			.contentLayout {
				margin-top: 20rpx;
				display: flex;
				gap: 20rpx;

				img {
					width: 180rpx;
					height: 180rpx;
				}

				.item-right {
					flex: 1;

					.bunns {
						font-weight: 400;
						font-size: 28rpx;
						color: #333;
						line-height: 40rpx;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.item-right-bottom {
						margin-top: 27rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						line-height: 38rpx;
					}

					>view {
						display: flex;
						justify-content: space-between;
					}
				}
			}

			.flexa {
				display: flex;
				justify-content: space-between;

				.text {
					display: flex;
					justify-items: center;
					align-items: center;

					img {
						width: 15rpx;
						height: 15rpx;
						margin-left: 10rpx;

					}
				}

				.text1 {
					margin-left: 20rpx;
					color: #b4b4b4;
				}

			}

		}

	}
</style>